package com.chz.SupermarketMS.service;

import com.chz.SupermarketMS.dao.CommodityRepository;
import com.chz.SupermarketMS.entities.Commodity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommodityService {
    @Autowired
    CommodityRepository commodityRepository;

//    调用数据接入层方法保存数据到数据库
    public Commodity save(Commodity commodity){
        return commodityRepository.save(commodity);
    }

//    定义getAll方法为调用学生数据接入层的findAll方法
    public List<Commodity> getAll(){
        return commodityRepository.findAll();
    }

//    通过commodityId来查询commodity实体
    public Iterable<Commodity> findAllById(List<Long> commodities) {
        return null;
    }

    public List<Commodity> findAll() {
        return  commodityRepository.findAll();
    }


    public Commodity findByCommodityId(long theId) {
        return commodityRepository.findByCommodityId(theId);
    }

    public void delete(Commodity theCommodity) {

        commodityRepository.delete(theCommodity);
    }
}

